
#include <daha.h>
#include <stdio.h>
#include <mm.h>
#include <pm.h>
#include <sched.h>

/*
int main(int argc, char *argv[]){
	return boot_daha();
}
*/
struct process *daha;
/*
 * Boot the kernel. Probe hardware and initialize data structures etc.
 * For demo (running inside another OS), this function must be called explicitly.
 * When running for real, this function would be called by the boot loader.
 */ 
int boot_daha(void /* for now */){
	int size = 0;
	int pages = 0;
	int i = 0;
  init_mm();
	init_pm();
	init_sched();
	size = get_pm_size() + get_sched_size() + get_mm_size();
	pages = size/PAGE_SIZE + 1;
	daha = new_process(0, "0x0", 0, pages);
	for(i = 0; i < pages; i++)
	{
		handle_page_fault(daha, i);
		bs_interrupt();
	}
	printf("Kernel booted.\n");
	printf("Page size is %d bytes\n",PAGE_SIZE);
	printf("Total main memory is %d bytes (%d kb) (%d pages)\n",MAIN_SIZE,MAIN_SIZE/1024,MAIN_PAGES);
	printf("Total backing store is %d bytes (%d mb) (%d pages)\n",BS_SIZE,BS_SIZE/(1024*1000),BS_PAGES);
	printf("Total OS size=%d bytes (%d pages).\n",size, pages);
	return 0;
}

int shutdown_daha(void /* for now */){
	queue_to_terminated(daha);
	terminate_process(daha);
	printf("Kernel unloaded\n");
	return 0;
}
